package com.xidian.zhiancloud.service.riskcontrol;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.xidian.zhiancloud.dao.riskcontrol.TRiskLedgerStatusMapper;
import com.xidian.zhiancloud.model.riskcontrol.TRiskLedgerStatusList;
import com.xidian.zhiancloud.model.riskcontrol.entity.TRLedgerStaGY00Entity;
import com.xidian.zhiancloud.model.riskcontrol.entity.TRLedgerStaSS00Entity;
import com.xidian.zhiancloud.model.riskcontrol.entity.TRLedgerStaZY00Entity;
import com.xidian.zhiancloud.qo.BaseReqQuery;
import org.apache.commons.beanutils.ConvertUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * 风险管控-风险台账
 */
@Service
public class TRiskLedgerStatusServicve extends ServiceImpl<TRiskLedgerStatusMapper,
        TRiskLedgerStatusList> {

    @Autowired
    TRiskLedgerStatusMapper tRiskLedgerStatusMapper;

    @Autowired
    HttpServletRequest request;

    //设备设施
    public Page<TRLedgerStaSS00Entity> getLedgerStaSS00Data
    (BaseReqQuery reqdata,String locale,String unit,
     String levelRisk,Long companyId){
        PageHelper.startPage(reqdata.getPageNum(), reqdata.getPageSize());
        return tRiskLedgerStatusMapper.getLedgerStaSS00Data
                (reqdata.getSearchKey(),locale,unit,levelRisk,companyId);
    }

    //作业活动
    public Page<TRLedgerStaZY00Entity> getLedgerStaZY00Data
    (BaseReqQuery reqdata,String locale,String unit,
     String levelRisk,Long companyId){
        return tRiskLedgerStatusMapper.getLedgerStaZY00Data
                (reqdata.getSearchKey(), locale,unit,levelRisk,companyId);
    }

    //工艺节点
    public Page<TRLedgerStaGY00Entity> getLedgerStaGY00Data
    (BaseReqQuery reqdata,String locale,String unit,
     String levelRisk,Long companyId){
        return tRiskLedgerStatusMapper.getLedgerStaGY00Data
                (reqdata.getSearchKey(),locale,unit,levelRisk,companyId);
    }

    //全部
    public Page<TRLedgerStaGY00Entity> getLedgerStaData(BaseReqQuery reqdata,String locale,
           String unit,String levelRisk,Long companyId){
        return tRiskLedgerStatusMapper.getLedgerStaData
            (reqdata.getSearchKey(),locale,unit,levelRisk,companyId);
    }
    
    public int insertLedgerStaList
            (List<TRiskLedgerStatusList> riskLedgerSta){
        return tRiskLedgerStatusMapper.insertLedgerStaList(riskLedgerSta);
    }

    //设备设施
    public Page<TRLedgerStaSS00Entity> getExportLedgerStaSS00Data
    (Long companyId, String id){
        List<Object> list=getObjeList(id);
        return tRiskLedgerStatusMapper.getExportLedgerStaSS00Data
                (companyId,list);
    }

    //作业活动
    public Page<TRLedgerStaZY00Entity> getExportLedgerStaZY00Data
    (Long companyId, String id){
        List<Object> list=getObjeList(id);
        return tRiskLedgerStatusMapper.getExportLedgerStaZY00Data
                (companyId,list);
    }

    //工艺节点
    public Page<TRLedgerStaGY00Entity> getExportLedgerStaGY00Data
    (Long companyId, String id){
        List<Object> list=getObjeList(id);
        return tRiskLedgerStatusMapper.getExportLedgerStaGY00Data
                (companyId,list);
    }

    public List<TRiskLedgerStatusList> getRiskLedgerDetails(Long companyId, String id){
        return tRiskLedgerStatusMapper.getRiskLedgerDetails(companyId,id);
    }

    public List<Object> getObjeList(String ids) {
        List<Object> list = new ArrayList<Object>();
        String[] str = ids.split(",");
        long[] strArrNum = (long[]) ConvertUtils.convert(str,long.class);
        for (Long id : strArrNum) {
            list.add(id);
        }
        return list;
    }

    public int updateRiskLedgerDetails(String id){
        String majorFactors=request.getParameter("majorFactors");
        String Leadconse=request.getParameter("Leadconse");
        String warnSign=request.getParameter("warnSign");
        String dutyCall=request.getParameter("dutyCall");
        String firstAidExt=request.getParameter("firstAidExt");
        String fireTel=request.getParameter("fireTel");
        String riskInfoCont=request.getParameter("riskInfoCont");
        return tRiskLedgerStatusMapper.updateRiskLedgerDetails(id,majorFactors,Leadconse,warnSign,dutyCall,firstAidExt,fireTel,riskInfoCont);
    }
    public List<TRiskLedgerStatusList> getImportantRisk(String levelRisk){
        return tRiskLedgerStatusMapper.getImportantRisk(levelRisk);
    }

}
